<%@ page language="java" pageEncoding="UTF-8"%>

<%
    String strFlowSetID = (String)request.getParameter("flowTemplateID");//流程ID xml文件以流程ID命名

    String strFlowSetName = (String)request.getParameter("FlowSetName");
    String strStatus = (String)request.getParameter("Status");
    strStatus = "01"; 
    request.getSession().setAttribute("Status",strStatus);
    String strFlag = (String)request.getParameter("flag"); //02 修改 01 查看
    strFlag = "02"; 
    String strFL_ID = (String)request.getParameter("FL_ID");//流程分类ID

 %>
<html xmlns:v="urn:schemas-microsoft-com:vml">
<HEAD>
<TITLE> </TITLE>
<META NAME="Keywords" CONTENT="WebFlow">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link href="inc/style.css" type=text/css rel=stylesheet>		

<script language=jscript src="inc/contextMenu/context.js"></script>
<script language=jscript src="inc/webflow.js"></script>
<script language=jscript src="inc/function.js"></script>
<script language=jscript src="inc/shiftlang.js"></script>
<script language=jscript src="inc/movestep.js"></script>

<SCRIPT LANGUAGE="JScript"> 
//alert('<%=strFlowSetID%>+@@+<%=strFlowSetName%>+@@+<%=strStatus%>+@@+<%=strFlag%>+@@+<%=strFL_ID%>');
var LANG = navigator.browserLanguage;
if (LANG.indexOf('en') > -1){
    LANG = 'en';
}
if (LANG.indexOf('zh') > -1){
    LANG = 'zh';
}
//alert(LANG);
function saveToXML(){
	//alert(1234);
  <%if("02".equals(strStatus)){%> //发布
     var flag=checkXML();
     if(!flag) {
     	return false;
     }
  <%}else{%>
  	fm.actionType.value="saveToXML";
        //fm.EditType.value="update";
    fm.FlowXML1.value=document.all.FlowXML.value; 
    	//alert(fm.FlowXML1.value);
    var strURL = "/ZhongChengLM/flowTemplateNodeAction!parseXMLAndSave.action";
    fm.action = strURL;
    	//fm.target="frainner";
    fm.submit();
    alert("保存成功！");
  <%}%>
}

	   var xmlHttp;
	
	   function createXMLHttpRequest() {
			if (window.ActiveXObject) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} else if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
			}
		}
		
		function checkUser(flowSetId,userCode,comCode,roleId) {
			createXMLHttpRequest();					
			var saveURL = "/risk/flow/CheckFlowChart.jsp?userCode="+userCode+"&comCode="+comCode+"&roleCode="+roleId;				
			xmlHttp.open("GET",saveURL,true);				
			xmlHttp.onreadystatechange = callback;				
			xmlHttp.send(null);
		}    
   		
		  		
		function callback() { 
			if (xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {	
				   // alert(xmlHttp.readyState);
				   if(xmlHttp.responseText ==0){			    
				        alert("您还有未设置的接收对象不存在"); 
					   return false;	
		        }
		     }
		  }}






  function checkXML(){
 var xmlDoc2 = new ActiveXObject('MSXML2.DOMDocument');
  xmlDoc2.async = false;
  xmlDoc2.loadXML(FlowXML.value);
  var xmlRoot2 = xmlDoc2.documentElement;
  var Steps = xmlRoot2.getElementsByTagName("Steps").item(0);
 var flowSetId="<%=strFlowSetID%>";
  for ( var i = 0;i < Steps.childNodes.length;i++ ) {
    Step = Steps.childNodes.item(i);
    var comCode = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("comCode");
    var roleCode = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("roleCode");
    var userCode = Step.getElementsByTagName("BaseProperties").item(0).getAttribute("userCode");
    var txt=Step.getElementsByTagName("BaseProperties").item(0).getAttribute("text");
	var fl1=false;
	var fl2=false;
	var fl3=false;
	if(comCode!=null&&comCode!=""){
	 fl1=true;
	} 

   if(roleCode!=null&&roleCode!=""){
	 fl2=true;
	} 
	if(userCode!=null&&userCode!=""){
	 fl3=true;
	} 
	
	if(fl1||fl2||fl3){
	////***************edit by arison  checkUser(flowSetId,userCode,comCode,roleCode); 
     continue;
	}else{
	alert("请完善结点\""+txt+"\"流程属性相关信息");
     return false;
	}
  }
  
 fm.actionType.value="saveToXML";
          //fm.EditType.value="update";
          fm.FlowXML1.value=document.all.FlowXML.value; 
          var strURL = "/risk/Flow.do";
        	fm.action = strURL;
        	//fm.target="frainner";
            fm.submit();
    alert("保存成功！");
    
 // return true;
  }
function loadFromXML(){
try{
  var f;
  var filename; 
  f = fm.FlowSetID.value;
  filename=f+'.xml';
     if (filename==''){
      alert('请先选择要导入的流程！');
	 return;
 }

  var xmlDoc = new ActiveXObject('MSXML2.DOMDocument');//MSXML2.DOMDocument  Microsoft.XMLDOM
  xmlDoc.async = false;
  var flag = xmlDoc.load('flows/'+filename);
  if (!flag) {    
     flag = xmlDoc.load('flows/default.xml')
  }
  var xmlRoot = xmlDoc.documentElement;
  FlowXML.value = xmlRoot.xml;
  }catch(error){
  	for(var p in error){
     document.writeln(p+"="+error[p]+"<br />");
	}
  }
}

function about(){
  var dialogAbout = window.showModalDialog("_about.jsp", window, "dialogWidth:460px; dialogHeight:373px; center:yes; help:no; resizable:no; status:no") ;
}
//-->
</SCRIPT>
<STYLE>
v\:* { Behavior: url(#default#VML) }
</STYLE>
</HEAD>

<BODY  onload='shiftLanguage(LANG,"main");document.title+=" Build "+document.lastModified;loadFromXML()' oncontextmenu="cleancontextMenu();return false;" scroll="auto" >

<form name="fm" method = "post">
<input type="hidden" name="actionType"/>
<INPUT name="FlowXML1" type="hidden" />
<INPUT name="Status" type="hidden"  value = "<%=strStatus %>">
<INPUT name="FlowSetID" type="hidden"  value = "<%=strFlowSetID %>">
<INPUT name="FlowSetName" type="hidden"  value ="<%=strFlowSetName %>">
<INPUT name="FL_ID" type="hidden"  value ="<%=strFL_ID %>">

</form>
<INPUT TYPE="hidden" name=FlowXML onpropertychange='if(AUTODRAW) redrawVML();'>
<TABLE border=0>

<TR>
	<TD width="" height="20">
	<TABLE cellspacing="0" cellpadding="0" class="panel_style">	
	
	<TR>
	<TD><SELECT NAME="flowList" style="display:none" class=txtput></SELECT> 
	<INPUT id=btnLoadFlow type="hidden" class="button"  value="导入流程" onclick='loadFromXML()' onfocus='this.blur()'></TD>
		<TD>&nbsp;</TD>
	 	<%
		if(strFlag.equals("01")){
		%>
	  <TD><INPUT id="btnEditFlow" type="hidden" class="button" value="修改流程" onclick='editFlow()' onfocus='this.blur()'></TD>
		<TD>&nbsp;</TD>
		<TD><INPUT id="btnSaveFlow" type="hidden" class="button"  value="保存流程" onclick='saveToXML()' onfocus='this.blur()'></TD>
		<TD>&nbsp;</TD>
		<TD><INPUT id="btnExit" TYPE="hidden" class="button" value="退出流程" onclick='javascript:history.back(-1);' onfocus='this.blur()'></TD>
		<TD></TD>
		<% 
		}else{
		 %>
		<TD><INPUT id="btnEditFlow" type="hidden" class="button" value="修改流程" onclick='editFlow()' onfocus='this.blur()'></TD>
		<TD>&nbsp;</TD>
		<TD><INPUT id="btnSaveFlow" type="button" class="button"  value="保存流程" onclick='saveToXML()' onfocus='this.blur()'></TD>
		<TD>&nbsp;</TD>
		<TD><INPUT id="btnExit" TYPE="button" class="button" value="退出流程" onclick='javascript:history.back(-1);' onfocus='this.blur()'></TD>
		<TD></TD>
		<%
		}
		%>
	</TR>	
	<TR>
	<TD colspan=2 width="1000" height="700" onclick="cleancontextMenu();return false;" oncontextmenu='flowContextMenu();return false;' valign=top align=left>
    <v:group ID="FlowVML"  style="left:5;top:26;width:950px;height:700px;position:absolute;" coordsize="2000,2000">
	</v:group>
	
	</TD> 
	</TR>			
	</TABLE>
	</TD>
</TR>
</TABLE>
 
<TABLE>

</TABLE>
<SCRIPT LANGUAGE="JavaScript">
</SCRIPT>
</BODY>
</HTML>
